package MyOop04;

import java.util.Scanner;

/**
 * 金额转换
 */
public class StringDemo006 {
    public static void main(String[] args) {
        //控制台输入金额
        Scanner scanner = new Scanner(System.in);
        int money;
        while (true){
            System.out.println("请输入一个金额：");
            money = scanner.nextInt();
            if (money < 0) {
                System.out.println("金额无效，请重新输入：");
            }else {
                break;
            }
        }

        //调用方法 数字变大写
        String str  = "";
        while (true){
            //取个位数
            int ge =money%10;
            int number = ge;
            String str1 = getCapitalNumber(number);
            str = str1+str;
            //为下一次循环提供一个新的money
            money = money/10;
            if (money==0){
                break;
            }
        }
        System.out.println(str);
        //前面补零补齐七位
        int count = 7 - str.length();
        for (int i = 0; i < count; i++) {
            str = "零" +str;
        }
        System.out.println(str);

        //插入单位
        //先定义一个数组

        String[] arr = {"佰","拾","万","仟","佰","拾","元",};
        for (int i = 0; i <arr.length; i++) {
            char c = str.charAt(i);
            String str2 = c + arr[i];
            System.out.print(str2);
        }
    }
    //定义一个方法数字转换成大写
    public static String getCapitalNumber(int number){
        //定义一个数组
        String[] arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        //数字的大小就是数组的下标。
        return arr[number];
    }
}
